package io.aicn.lowcode.entity.dbmanager;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

/**
 * 数据源配置实体类
 * 
 * @author lowcode-generator
 * @since 2025-01-25
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("dbm_datasource")
public class DataSource {

    /**
     * 主键ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 数据源名称
     */
    @TableField("name")
    private String name;

    /**
     * 数据库类型(mysql/postgresql)
     */
    @TableField("type")
    private String type;

    /**
     * 主机地址
     */
    @TableField("host")
    private String host;

    /**
     * 端口号
     */
    @TableField("port")
    private Integer port;

    /**
     * 数据库名
     */
    @TableField("database_name")
    private String databaseName;

    /**
     * 用户名
     */
    @TableField("username")
    private String username;

    /**
     * 密码(加密)
     */
    @TableField("password")
    private String password;

    /**
     * 连接状态
     */
    @TableField("status")
    private String status;

    /**
     * 扩展配置(JSON格式)
     */
    @TableField("config")
    private String config;

    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    /**
     * 创建人
     */
    @TableField(value = "create_by", fill = FieldFill.INSERT)
    private String createBy;

    /**
     * 更新人
     */
    @TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
    private String updateBy;

    /**
     * 数据源状态枚举
     */
    public enum Status {
        CONNECTED("connected", "已连接"),
        DISCONNECTED("disconnected", "未连接"),
        ERROR("error", "连接错误");

        private final String code;
        private final String description;

        Status(String code, String description) {
            this.code = code;
            this.description = description;
        }

        public String getCode() {
            return code;
        }

        public String getDescription() {
            return description;
        }
    }

    /**
     * 数据库类型枚举
     */
    public enum DatabaseType {
        MYSQL("mysql", "MySQL"),
        POSTGRESQL("postgresql", "PostgreSQL");

        private final String code;
        private final String description;

        DatabaseType(String code, String description) {
            this.code = code;
            this.description = description;
        }

        public String getCode() {
            return code;
        }

        public String getDescription() {
            return description;
        }
    }
}